<template>
  <div class="box" ref="targetElement">
    <div class="search-box" ref="searchBox">
      <div class="search-top-box">
        <div class="search-top-left-box">
          <el-form ref="div" :inline="true" :model="formSearch" @submit.native.prevent label-width="110px"
            class="demo-form-inline">
            <el-form-item label="项目名称">
              <el-input @change="onSearch(1)" clearable class="form-width" v-model="formSearch.project_name"
                placeholder="输入项目名称"></el-input>
            </el-form-item>
            <el-form-item label="项目类型">
              <el-select filterable @change="onSearch(1)" clearable class="form-width"
                v-model="formSearch.store_type_id" placeholder="选择项目类型">
                <el-option v-for="(item, index) in storeTypeList" :key="index" :label="item.store_type_name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="项目进度">
              <el-select multiple collapse-tags filterable @change="onSearch(1)" clearable class="form-width"
                v-model="formSearch.display_status" placeholder="选择项目进度">
                <el-option v-for="(item, index) in displayStatusList" :key="index" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="项目编号">
              <el-input @change="onSearch(1)" clearable class="form-width" v-model="formSearch.project_number"
                placeholder="输入项目编号"></el-input>
            </el-form-item>
            <!-- 展开显示 -->
            <template v-if="moreSearchShow">
              <el-form-item label="项目品牌">
                <el-select @change="onSearch(1)" filterable clearable class="form-width" v-model="formSearch.brand_id"
                  placeholder="选择项目品牌">
                  <el-option v-for="(item, index) in brandList" :key="index" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="省市区">
                <el-cascader @change="onSearch(1)" placeholder="选择省市区" :props="{
                  value: 'id',
                  label: 'name'
                }" v-model="formSearch.city" :options="areaList" clearable class="form-width"></el-cascader>
              </el-form-item>
              <el-form-item label="项目创建时间">
                <el-date-picker @change="onSearch(1)" class="form-width" value-format="yyyy-MM-dd"
                  v-model="formSearch.created_at" type="daterange" placeholder="选择日期" range-separator="至"
                  start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="综合平均评分">
                <el-select filterable @change="onSearch(1)" clearable class="form-width"
                  v-model="formSearch.overall_rating" placeholder="综合平均评分">
                  <el-option label="1分" :value="1"></el-option>
                  <el-option label="2分" :value="2"></el-option>
                  <el-option label="3分" :value="3"></el-option>
                  <el-option label="4分" :value="4"></el-option>
                  <el-option label="5分" :value="5"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="客户经理">
                <el-select filterable @change="onSearch(1)" clearable class="form-width"
                  v-model="formSearch.account_manager_id" placeholder="选择客户经理">
                  <el-option v-for="(item, index) in accountManagerList" :key="index" :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="施工工程经理">
                <el-select filterable @change="onSearch(1)" clearable class="form-width"
                  v-model="formSearch.engineering_manager_id" placeholder="选择施工工程经理">
                  <el-option v-for="(item, index) in engineeringManagerList" :key="index" :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="工程监理">
                <el-select filterable @change="onSearch(1)" clearable class="form-width"
                  v-model="formSearch.engineering_supervision_id" placeholder="选择工程监理">
                  <el-option v-for="(item, index) in engineeringSupervisionList" :key="index" :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="客户名称">
                <el-select filterable @change="onSearch(1)" clearable class="form-width" v-model="formSearch.user_name"
                  placeholder="选择客户">
                  <el-option v-for="(item, index) in customerList" :key="index" :label="item.name" :value="item.name">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="合同开工日期">
                <el-date-picker @change="onSearch(1)" class="form-width" value-format="yyyy-MM-dd"
                  v-model="formSearch.contract_commencement_date" type="daterange" placeholder="选择日期"
                  range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="合同完工日期">
                <el-date-picker @change="onSearch(1)" class="form-width" value-format="yyyy-MM-dd"
                  v-model="formSearch.contract_completion_date" type="daterange" placeholder="选择日期" range-separator="至"
                  start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="施工进度">
                <el-select filterable @change="onSearch(1)" clearable class="form-width"
                  v-model="formSearch.construction_status" placeholder="选择施工进度">
                  <el-option label="待进场" :value="42"></el-option>
                  <el-option label="施工中" :value="45"></el-option>
                  <el-option label="已完工" :value="50"></el-option>
                  <el-option label="质保中" :value="60"></el-option>
                  <el-option label="质保到期" :value="70"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="验收进度">
                <el-input @change="onSearch(1)" clearable class="form-width" v-model="formSearch.acceptance_progress"
                  placeholder="输入验收进度"></el-input>
              </el-form-item>
              <el-form-item label="风险标签">
                <el-select filterable @change="onSearch(1)" clearable class="form-width" v-model="formSearch.risk_label"
                  placeholder="选择风险标签">
                  <el-option label="一次预警" value="一次预警"></el-option>
                  <el-option label="二次预警" value="二次预警"></el-option>
                  <el-option label="已超期" value="已超期"></el-option>
                  <el-option label="停工" value="停工"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="结算完成时间">
                <el-date-picker @change="onSearch(1)" class="form-width" value-format="yyyy-MM-dd"
                  v-model="formSearch.settlement_completion_date" type="daterange" placeholder="选择日期"
                  range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="售后截止日期">
                <el-date-picker @change="onSearch(1)" class="form-width" value-format="yyyy-MM-dd"
                  v-model="formSearch.warranty_deadline_date" type="daterange" placeholder="选择日期" range-separator="至"
                  start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </template>
          </el-form>
        </div>
        <div class="search-top-right-box">
          <p @click="moreSearchFunc">
            {{ moreSearchShow ? "收起" : "展开"
            }}<i :class="moreSearchShow ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
          </p>
          <el-button type="primary" @click="onSearch(1)">查询</el-button>
          <el-button type="primary" @click="addProjectFunc" v-if="$isPer(permission, ['project_add'])">新增项目</el-button>
        </div>
      </div>
    </div>
    <!-- table -->
    <div class="page-list" ref="pageList" v-loading="pageLoading">
      <div class="list-top-box" ref="listTopBox">
        <div class="tab-box">
          <el-tabs v-model="formSearch.to_do" @tab-click="onSearch(1)">
            <el-tab-pane label="全部" name="0"></el-tab-pane>
            <el-tab-pane label="待处理" name="1"></el-tab-pane>
            <el-tab-pane label="待收款" name="2"></el-tab-pane>
          </el-tabs>
        </div>
        <div class="list-top-box-right">
          <p class="list-top-box-left">
            已选<span class="num">{{ multipleSelection.length }}</span>/{{ tableData.length }}数据
          </p>
          <!-- 项目流程操作按钮 -->
          <div class="btns">
            <el-button type="primary" @click="exportVisible = true" :disabled="tableData.length == 0"
              v-if="$isPer(permission, ['sale_exportSaleProjectExcel'])">导出项目列表</el-button>
            <el-button type="primary" :disabled="XMimprove" @click="editProjectFunc"
              v-if="$isPer(permission, ['projects_updProject'])">项目完善</el-button>
            <el-button type="primary" :disabled="XMstart" @click="startProjectFunc"
              v-if="$isPer(permission, ['projects_chooseSurveySite'])">项目启动</el-button>
            <el-button type="primary" :disabled="SQquotation" @click="SQquotationFunc"
              v-if="$isPer(permission, ['project_sqbj'])">申请报价</el-button>
            <el-button type="primary" @click="DKquotationFunc" v-if="$isPer(permission, ['project_dkbj'])"
              :disabled="DKquotation">对客报价</el-button>
            <el-button v-if="$isPer(permission, ['projects_reQuote'])" type="primary" :disabled="reQuote"
              @click="projectsQuoteFunc">重新报价</el-button>
            <el-button v-if="$isPer(permission, ['projects_reSettlement'])" type="primary" :disabled="reSettlement"
              @click="projectsSettlementFunc">重新结算</el-button>
            <el-button type="primary" :disabled="QRzjx" @click="QRzjxFunc"
              v-if="$isPer(permission, ['projects_confirmIsChangeItem'])">发起结算单</el-button>
            <el-button v-if="$isPer(permission, ['skd_add'])" type="primary" :disabled="multipleSelection.length != 1"
              @click="addReceiptFunc">新增收款单</el-button>
            <el-button type="primary" :disabled="changeMan" @click="changeManFunc"
              v-if="$isPer(permission, ['common_updProjectLeader'])">更换客户经理</el-button>
            <el-button type="primary" :disabled="FPccountManager" @click="FPassignAccountManagerFunc"
              v-if="$isPer(permission, ['projects_assignAccountManager'])">分配客户经理</el-button>
            <el-button v-if="$isPer(permission, ['projects_projectRollback'])" type="primary" :disabled="XMback"
              @click="adminBackDataFunc">项目回退</el-button>
            <el-button :disabled="XMcancel" @click="XmcancelFunc"
              v-if="$isPer(permission, ['projects_projectCancellation'])">项目取消</el-button>

            <el-button type="danger" plain :disabled="multipleSelection.length == 0" @click="delProjectFunc"
              v-if="$isPer(permission, ['projects_delProject'])">删除</el-button>
          </div>
        </div>
      </div>
      <div class="table-box" ref="tableBox">
        <el-table border ref="table" height="100%" @row-click="handleHighlightChangeTable" highlight-selection-row
          :header-cell-style="{
            background: '#FAFBFC',
            color: '#828A9D',
            textAlign: 'center',
          }" :cell-style="{ textAlign: 'center', color: '#1B2431' }" :data="tableData" style="width: 100%"
          v-loading="tableLoading" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="80"></el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmmc')" min-width="180px" fixed="left" prop="project_name"
            label="项目名称" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmbh')" min-width="130px" fixed="left" prop="project_number"
            label="项目编号" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-button v-if="$isPer(permission, ['project_detail'])" type="text"
                @click.stop="goToDetail(scope.row)">{{
                  scope.row.project_number || '--'
                }}</el-button>
              <span v-else>{{ scope.row.project_number || '--' }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmpp')" min-width="120px" fixed="left" prop="brand_name"
            label="项目品牌" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag :color="`${scope.row.brand_colour}`" style="color: #ffffff;">
                {{ scope.row.brand_name }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmlx')" min-width="120px" prop="store_type_name" label="项目类型"
            show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.store_type_name || '--' }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmjd')" min-width="150px" prop="address" label="项目进度"
            show-overflow-tooltip>
            <template slot-scope="scope">
              <div class="flex ac jc">
                <span v-if="scope.row.display_status == 10">待启动</span>
                <span v-if="scope.row.display_status == 15">待勘场</span>
                <span v-if="scope.row.display_status == 18">待勘场出图</span>
                <span v-if="scope.row.display_status == 20">出图中</span>
                <span v-if="scope.row.display_status == 25">待报价</span>
                <span v-if="scope.row.display_status == 30">洽谈中</span>
                <span v-if="
                  scope.row.display_status >= 40 &&
                  scope.row.display_status != 70
                ">
                  已签约
                </span>
                <span v-if="scope.row.display_status == 42">-待进场</span>
                <span v-if="scope.row.display_status == 45">-施工中</span>
                <span v-if="scope.row.display_status == 50">-已完工</span>
                <span v-if="scope.row.display_status == 55">-待结算</span>
                <span v-if="scope.row.display_status == 60">-款项付清</span>
                <span v-if="scope.row.display_status == 70">项目取消</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmssq')" min-width="180px" prop="area" label="省市区"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_dqjd')" min-width="180px" prop="current_node" label="当前节点"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.current_node || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmcjsj')" min-width="180px" prop="created_at" label="项目创建时间"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_zhpjpf')" min-width="110px" prop="overall_rating" label="综合平均评分"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.overall_rating ? scope.row.overall_rating + '分' : '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_khjl')" min-width="120px" prop="account_manager_name" label="客户经理"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.account_manager_name || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_sggcjl')" min-width="120px" prop="engineering_manager_name"
            label="施工工程经理" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.engineering_manager_name || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_gcjl')" min-width="120px" prop="engineering_supervision_name"
            label="工程监理" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.engineering_supervision_name || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_khmc')" min-width="120px" prop="user_name" label="客户名称"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.user_name || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_htzt')" min-width="100px" prop="contract_status" label="合同状态"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.contract_status == 1 ? '未签约' : '已签约' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_htqysj')" min-width="120px" prop="signing_date" label="合同签约日期"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.signing_date || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_htkgrq')" min-width="110px" prop="contract_commencement_date"
            label="合同开工日期" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.contract_commencement_date || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_htwgrq')" min-width="110px" prop="contract_completion_date"
            label="合同完工日期" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.contract_completion_date || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_htgq')" min-width="100px" prop="contract_duration_days" label="合同工期"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.contract_duration_days ? scope.row.contract_duration_days + '天' : '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_htqyje')" min-width="120px" prop="contract_price" label="合同签约金额"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.contract_price + '' ? scope.row.contract_price + '元' : '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_qybjb')" min-width="100px" prop="quotation_ratio" label="签约报价比"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.quotation_ratio ? scope.row.quotation_ratio + '%' : '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_sgjd')" min-width="100px" prop="construction_status" label="施工进度"
            show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.construction_status == 30">待进场</span>
              <span v-if="scope.row.construction_status == 35">待进场</span>
              <span v-if="scope.row.construction_status == 40">待进场</span>
              <span v-if="scope.row.construction_status == 42">待进场</span>
              <span v-if="scope.row.construction_status == 45">施工中</span>
              <span v-if="scope.row.construction_status == 50">已完工</span>
              <span v-if="scope.row.construction_status == 60">质保中</span>
              <span v-if="scope.row.construction_status == 70">质保到期</span>
              <span v-if="!scope.row.construction_status">--</span>
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_ysjd')" min-width="150px" prop="acceptance_progress" label="验收进度"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.acceptance_progress || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_fxbq')" min-width="100px" prop="risk_label" label="风险标签"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.risk_label || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_cjjssj')" min-width="110px" prop="settlement_start_date"
            label="出具结算时间" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.settlement_start_date || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_yjsje')" min-width="120px" prop="settlement_amount" label="应结算金额"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.settlement_amount + '' ? scope.row.settlement_amount + '元' : '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_sjjsje')" min-width="120px" prop="final_settlement_amount"
            label="实际结算金额" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.final_settlement_amount + '' ? scope.row.final_settlement_amount + '元' : '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_jsyhje')" min-width="120px" prop="settlement_discount_amount"
            label="结算优惠金额" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.settlement_discount_amount + '' ? scope.row.settlement_discount_amount + '元' : '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_jswcsj')" min-width="110px" prop="settlement_completion_date"
            label="结算完成时间" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.settlement_completion_date || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_jssx')" min-width="100px" prop="settlement_validity" label="结算时效"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.settlement_validity ? scope.row.settlement_validity + '天' : '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmysk')" min-width="110px" prop="paid_amount" label="项目已收款"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.paid_amount + '元' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_xmwsk')" min-width="110px" prop="unpaid_amount" label="项目未收款"
            show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.unpaid_amount + '元' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_shjzrq')" min-width="110px" prop="warranty_deadline_date"
            label="售后截止日期" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.warranty_deadline_date || '--' }}
            </template>
          </el-table-column>
          <el-table-column v-if="$fieldShowFunc('xm_sfzzbqn')" min-width="120px" prop="settlement_completion_date"
            label="是否在质保期内" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.status >= 1150 ? scope.row.is_sell_by == 1 ? '是' : '否' : '--' }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="page-footer">
        <el-pagination class="el-pagination" @current-change="handleCurrentChange" :current-page="page" :page-size="num"
          @size-change="handleSizeChange" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
    </div>
    <!-- 分配客户经理 -->
    <fpkhjlCom :project_id="multipleSelection.length ? multipleSelection[0].id : 0" :addDialogVisible="fpkhjlVisible"
      @onClose="fpkhjlVisible = false" @onSuccess="FPassignAccountManagerOnSuccess"></fpkhjlCom>
    <!-- 项目取消 -->
    <xmqxCom :project_id="multipleSelection.length ? multipleSelection[0].id : 0" :addDialogVisible="xmqxVisible"
      @onClose="xmqxVisible = false" @onSuccess="XmcancelOnSuccess"></xmqxCom>
    <!-- 确认增减项 -->
    <qrzjxCom :project_id="multipleSelection.length ? multipleSelection[0].id : 0" :addDialogVisible="qrzjxVisible"
      @onClose="qrzjxVisible = false" @onSuccess="QRzjxOnSuccess"></qrzjxCom>
    <!-- 导出项目列表 -->
    <el-dialog :modal-append-to-body="false" title="导出项目字段选择" :visible.sync="exportVisible" width="680px"
      :before-close="exportCloseFunc">
      <el-checkbox class="checkbox-item" v-model="allChecked" @change="allCheckedChangeFunc">全选</el-checkbox>
      <div>
        <div class="export-scroll">
          <el-checkbox-group v-model="exportrVal">
            <el-checkbox class="checkbox-item" v-for="(item, index) in exportArr" :key="index" :label="item.label"
              border></el-checkbox>
          </el-checkbox-group>
        </div>
        <p v-if="exportUrl">导出文件链接：<el-button @click="$openUrlFunc(exportUrl[0])" type="text">{{
          exportUrl[1]
            }}</el-button></p>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="exportSubmitFunc">提交</el-button>
        <el-button @click="exportCloseFunc">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 人员修改 -->
    <changeManCom :projectId="multipleSelection.length ? multipleSelection[0].id : 0"
      :changeDialogVisible="changeManVisible" :type="1" @changeManCancelFunc="changeManVisible = false"
      @changeManSuccessFunc="changeManSuccessFunc"></changeManCom>
    <!-- 回退项目 -->
    <el-dialog :modal-append-to-body="false" title="选择回退目标" :visible.sync="adminBackShow" width="400px"
      @close="adminBackShow = false">
      <el-select filterable style="width: 100%" v-model="backValue" placeholder="请选择">
        <el-option v-for="(item, index) in backOptions" :key="index" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="adminBackSubmit" :loading="backLoading">提交</el-button>
        <el-button @click="adminBackShow = false">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 新增收款单 -->
    <el-dialog :modal-append-to-body="false" :before-close="cancelReceiptFunc" destroy-on-close title="新增收款单"
      :visible.sync="dialogVisibleReceipt" width="600px">
      <el-form :rules="rulesReceipt" ref="ruleFormReceipt" :model="formInlineReceipt" label-width="100px"
        label-position="left">
        <el-form-item label="付款类型" prop="payment_type">
          <el-select @change="paymentTypeChangeFunc" filterable clearable v-model="formInlineReceipt.payment_type"
            placeholder="选择付款类型" class="form-width2">
            <el-option v-for="item in payTypeList" :key="item.id" :label="item.label" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目名称" prop="project_id">
          <el-select filterable clearable disabled v-model="formInlineReceipt.project_id" placeholder="选择项目名称"
            class="form-width2">
            <el-option v-for="item in tableData" :key="item.id" :label="item.project_name" :value="item.id">
            </el-option>
          </el-select>
          <template v-if="formInlineReceipt.payment_type == 4 && formInlineReceipt.settlementMsg">
            <div>
              <span style="color: #606266;">结算单：{{ formInlineReceipt.settlementMsg.settlement_number }}</span>
              <el-button style="padding: 0 0 0 10px;" type="text" @click="goSettlementMsFunc">查看详情</el-button>
            </div>
          </template>
        </el-form-item>
        <el-form-item label="项目已收款" v-if="formInlineReceipt.project_id">
          <el-input disabled class="form-width2" v-model="formInlineReceipt.paid_amount" placeholder=""></el-input>
        </el-form-item>
        <el-form-item label="项目未收款" v-if="formInlineReceipt.project_id">
          <el-input disabled class="form-width2" v-model="formInlineReceipt.unpaid_amount" placeholder=""></el-input>
        </el-form-item>
        <el-form-item label="增款项" v-if='formInlineReceipt.payment_type == 5' prop="change_id">
          <el-select filterable clearable v-model="formInlineReceipt.change_id" placeholder="选择增款项" class="form-width2">
            <el-option v-for="item in changeList" :key="item.id" :label="item.change_number" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收款金额" prop="amount_collected">
          <el-input v-input-limit="2" clearable class="form-width2" v-model="formInlineReceipt.amount_collected"
            placeholder="输入收款金额"></el-input>
        </el-form-item>
        <el-form-item label="收款账户" prop="receiving_account_id">
          <el-select filterable clearable v-model="formInlineReceipt.receiving_account_id" placeholder="选择付款类型"
            class="form-width2">
            <el-option v-for="item in companyList" :key="item.id" :label="item.account_name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input clearable class="form-width2" v-model="formInlineReceipt.remark" placeholder="输入备注"></el-input>
        </el-form-item>
        <el-form-item label="支付凭证" prop="payment_voucher">
          <div class="file-list-box">
            <div class="file-item-box" v-for="(item, index) in formInlineReceipt.payment_voucher" :key="index">
              <div class="el-icon-delete-box" @click="delFileFunc(index)">
                <i class="el-icon-error"></i>
              </div>
              <el-tooltip class="item" effect="dark" :content="item.name" placement="top">
                <el-image fit="cover" class="img" :src="$fileImgFunc(item)" :preview-src-list="[$fileImgFunc(item)]">
                </el-image>
              </el-tooltip>
            </div>

            <el-upload accept="image/*" class="avatar-uploader" action="#" :show-file-list="false" :auto-upload="false"
              list-type="picture-card" :on-change="paymentVoucherFileFunc">
              <i class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </div>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitReceiptFunc" :loading="addLoading">提交</el-button>
        <el-button @click="cancelReceiptFunc" :loading="addLoading">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 项目启动 -->
    <el-dialog :modal-append-to-body="false" :before-close="cancelStartFunc" destroy-on-close title="项目启动"
      :visible.sync="dialogVisibleStart" width="600px">
      <el-form :rules="rulesStart" ref="ruleFormStart" :model="formInlineStart" label-width="110px"
        label-position="left" :key="formInlineStart.survey_site">
        <el-form-item label="是否勘场">
          <el-radio-group class="form-width2" v-model="formInlineStart.survey_site" @change="surveySiteChangeFunc">
            <el-radio :label="1">无需勘场</el-radio>
            <el-radio :label="2">实地勘场</el-radio>
            <el-radio :label="3">勘场出图</el-radio>
          </el-radio-group>
        </el-form-item>
        <!--  :prop="formInlineStart.survey_site == 1 ? '' : 'survey_date'" -->
        <el-form-item label="约定勘场日期">
          <el-date-picker :disabled="formInlineStart.survey_site == 1" value-format="yyyy-MM-dd" clearable
            class="form-width2" v-model="formInlineStart.survey_date" type="date" placeholder="选择约定勘场日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="设计师" :prop="formInlineStart.survey_site == 1 ? '' : 'designer_id'">
          <el-select :disabled="formInlineStart.survey_site == 1" filterable clearable class="form-width2"
            v-model="formInlineStart.designer_id" placeholder="请选择设计师">
            <el-option v-for="item in designerList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitStartFunc" :loading="startLoading">提交</el-button>
        <el-button @click="cancelStartFunc" :loading="startLoading">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import adminApi from "@/api/adminApi";
import projectApi from "@/api/projectApi";
import commonApi from "@/api/common";
import brandApi from "@/api/brandApi";
import { getUserInfo } from "@/utils/auth";
import { backdata1, backdata2, backdata3 } from "@/utils/backData";
import saleApi from "@/api/saleApi";
import changeManCom from "@/components/changeManCom/index";//修改人员
import fpkhjlCom from "@/components/projectPopu/fpkhjlCom/index";//分配客户经理
import xmqxCom from "@/components/projectPopu/xmqxCom/index";//项目取消
import qrzjxCom from "@/components/projectPopu/qrzjxCom/index";//确认增减项
import storeTypeApi from "@/api/storeTypeApi";
import { xsProjectListFieldArr } from '@/utils/exportField';
import companyApi from "@/api/companyApi";
import increaseDecreaseItemsApi from "@/api/increaseDecreaseItemsApi";
import preSettlementApi from "@/api/preSettlementApi";


export default {
  name: "projectManagement",
  components: { fpkhjlCom, xmqxCom, qrzjxCom, changeManCom },
  data() {
    var validatepayment_voucher = (rule, value, callback) => {
      if (!value.length) {
        callback(new Error('请选择支付凭证'));
      } else {
        callback();
      }
    };
    return {
      // 项目回退
      backLoading: false,
      adminBackShow: false,
      backOptions: [],
      backValue: '',
      // 修改人员
      changeManVisible: false,
      // 导出项目
      exportVisible: false,//导出弹窗
      exportUrl: '',//导出url
      allChecked: false,//字段是否全选
      exportrVal: [],//已勾选字段
      exportArr: xsProjectListFieldArr,//字段列表


      // 确认增减项
      qrzjxVisible: false,
      // 项目取消
      xmqxVisible: false,
      // 分配客户经理
      fpkhjlVisible: false,
      tableLoading: false,
      userInfo: "",
      page: 1,
      tableData: [],
      formSearch: {
        to_do: '0',
        display_status: "",
        construction_status: "",
        engineering_manager_id: "",
        account_manager_id: "",
        brand_id: "",
        province_id: "",
        city_id: "",
        user_id: "",
        keyword: "",
      },
      moreSearchShow: false,
      page: 1,
      num: 10,
      total: 0,
      addLoading: false,
      project_id: "",
      // 项目进度筛选列表
      displayStatusList: [
        {
          label: "待启动",
          value: 10,
        },
        {
          label: "待勘场",
          value: 15,
        },
        {
          label: "待勘场出图",
          value: 18,
        },
        {
          label: "待方案设计",
          value: 20,
        },
        {
          label: "待报价",
          value: 25,
        },
        {
          label: "洽谈中",
          value: 30,
        },
        {
          label: "已签约",
          value: 400,
        },
        {
          label: "待进场",
          value: 42,
        },
        {
          label: "施工中",
          value: 45,
        },
        {
          label: "已完工",
          value: 50,
        },
        {
          label: "待结算",
          value: 55,
        },
        {
          label: "款项付清",
          value: 60,
        },
        {
          label: '已取消',
          value: 70
        }
      ],
      constructionStatusList: [
        {
          label: "待进场",
          value: 42,
        },
        {
          label: "施工中",
          value: 45,
        },
        {
          label: "已完工",
          value: 50,
        },
      ],
      brandList: [], //品牌列表
      accountManagerList: [], //客户经理
      engineeringManagerList: [], //工程经理
      customerList: [], //客户
      pageLoading: false,
      multipleSelection: [],//已选列表
      storeTypeList: [],//门店类型列表
      areaList: [],//省市区
      engineeringSupervisionList: [],//工程监理列表
      permission: [],//权限列表
      // 新增收款单
      formInlineReceipt: {
        project_id: "",
        payment_type: "",
        amount_collected: "",
        remark: "",
        receiving_account_id: "",
        payment_voucher: [],
        change_id: "",
        settlementMsg: '',
        unpaid_amount: '',
        paid_amount: ''
      },
      payTypeList: [{
        id: 1,
        label: '勘场费用',
        // status_arr: [1020],
      }, {
        id: 2,
        label: '预付款',
        // status_arr: [1105],
      }, {
        id: 3,
        label: '进度款',
        // progress_payment: 1
      }, {
        id: 4,
        label: '尾款',
      }, {
        id: 5,
        label: '增项款',
        // additional_payment: 1
      }, {
        id: 6,
        label: '定金',
        less_status: 1105,
      }],//收款单类型
      changeList: [],//增款项列表
      rulesReceipt: {
        project_id: [
          { required: true, message: '请选择项目名称', trigger: 'change' },
        ],
        payment_type: [
          { required: true, message: '请选择付款类型', trigger: 'change' },
        ],
        amount_collected: [{ required: true, message: '请输入收款金额', trigger: 'change' },],
        receiving_account_id: [
          { required: true, message: '请选择收款账户', trigger: 'change' },
        ],
        change_id: [{ required: true, message: '请选择增款项', trigger: 'change' }],
        payment_voucher: [
          { required: true, validator: validatepayment_voucher, trigger: 'change' },
        ],
      },
      dialogVisibleReceipt: false,
      companyList: [],//收款账户
      // 项目启动
      dialogVisibleStart: false,
      formInlineStart: {
        survey_site: 1,
        designer_id: "",
        survey_date: "",
      },
      startLoading: false,
      rulesStart: {
        designer_id: [
          { required: true, message: '请选择设计师', trigger: 'change' },
        ],
        survey_date: [
          { required: true, message: '请选择约定勘场日期', trigger: 'change' },
        ],
      },
      designerList: [],
      STATUS_CONSTANTS: {
        SIGNED: 400, // 已签约状态
        SIGNED_SUB_STATUSES: [40, 42, 45, 50] // 已签约的子状态
      }
    };
  },
  watch: {},
  computed: {
    // 重新回退到结算
    reSettlement() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 && (multipleSelection[0].status == 1140 || multipleSelection[0].status == 1145)) {
        return false;
      } else {
        return true;
      }
    },
    // 客户经理回退至重新报价
    reQuote() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 && (multipleSelection[0].status == 1095 || multipleSelection[0].status == 1100)) {
        return false;
      } else {
        return true;
      }
    },
    // 项目回退
    XMback() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 &&
        multipleSelection[0].status != 1500 &&
        multipleSelection[0].status != 1150 &&
        multipleSelection[0].status > 1010) {
        return false;
      } else {
        return true;
      }
    },
    // 修改人员 && this.userInfo.position_id == 10
    changeMan() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 &&
        multipleSelection[0].account_manager_name &&
        multipleSelection[0].status != 1150) {
        return false;
      } else {
        return true;
      }
    },
    // 确认增减项 && this.userInfo.position_id == 2
    QRzjx() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 &&
        multipleSelection[0].status == 1125) {
        return false;
      } else {
        return true;
      }
    },
    // 项目启动 && this.userInfo.position_id == 10
    XMstart() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 && multipleSelection[0].status == 1010) {
        return false;
      } else {
        return true;
      }
    },
    // 项目完善 && this.userInfo.position_id == 2
    XMimprove() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 && multipleSelection[0].status > 1000) {
        return false;
      } else {
        return true;
      }
    },
    // 项目取消 && this.userInfo.position_id == 10
    XMcancel() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 && multipleSelection[0].status != 1500) {
        return false;
      } else {
        return true;
      }
    },
    // 人员修改 && this.userInfo.position_id == 1
    RYchange() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1) {
        return false;
      } else {
        return true;
      }
    },
    // 分配客户经理 && this.userInfo.position_id == 1
    FPccountManager() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 && multipleSelection[0].status == 1000) {
        return false;
      } else {
        return true;
      }
    },
    // 申请报价 && this.userInfo.position_id == 2
    SQquotation() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 && multipleSelection[0].status == 1065) {
        return false;
      } else {
        return true;
      }
    },
    // 对客报价 && this.userInfo.position_id == 2
    DKquotation() {
      let multipleSelection = this.multipleSelection;
      if (multipleSelection.length == 1 && multipleSelection[0].status == 1095) {
        return false;
      } else {
        return true;
      }
    },
  },
  destroyed() {
    window.removeEventListener('resize', this.handleResize);
    // 移除窗口大小变化事件监听器，防止内存泄漏
    if (this.resizeObserver) {
      // 停止观察目标元素，防止内存泄漏
      this.resizeObserver.disconnect();
    }
  },
  activated() {
    // 监听窗口大小变化事件
    window.addEventListener('resize', this.handleResize);
    // 跳转过来判断（携带参数）
    this.hrefQueryFunc(() => {
      this.onSearch();
    });
  },
  deactivated() {
    window.removeEventListener('resize', this.handleResize);
    // 移除窗口大小变化事件监听器，防止内存泄漏
    if (this.resizeObserver) {
      // 停止观察目标元素，防止内存泄漏
      this.resizeObserver.disconnect();
    }
  },
  mounted() {
    this.handleResize();
    // 监听窗口大小变化事件
    window.addEventListener('resize', this.handleResize);
    // 操作权限
    this.$getHtmlAuthority(this.$route.path).then(res => {
      console.log(res, "getHtmlAuthority");
      this.permission = res.data.permission;
    })
    // 跳转过来判断（携带参数）
    this.hrefQueryFunc(() => {
      this.saleProjectList();//项目列表
      this.getBrandList();//品牌列表
      this.getStoreTypeList();//门店类型列表
      this.getAccountManager();//客户经理列表
      this.getEngineeringManager();//工程经理列表
      this.getCustomer();//客户列表
      this.getAreaList();//省市区
      this.getEngineeringSupervision();//工程监理列表
    })

    this.userInfo = getUserInfo();

    this.$nextTick(() => {
      let url = this.getnewurl();
      window.history.replaceState(null, null, url);
    });
  },
  methods: {
    handleResize() {
      const target = this.$refs.targetElement;
      const searchBox = this.$refs.searchBox;
      const pageList = this.$refs.pageList;
      const listTopBox = this.$refs.listTopBox;
      const tableBox = this.$refs.tableBox;
      // 创建 ResizeObserver 实例
      const resizeObserver = new ResizeObserver(entries => {
        setTimeout(() => {
          console.log('元素变为:', searchBox.offsetHeight, listTopBox.offsetHeight);
          // searchBox.offsetHeight + 'px'
          pageList.style.height = 'calc(100% - ' + (searchBox.offsetHeight + 15) + 'px)';
          tableBox.style.height = 'calc(100% - ' + (listTopBox.offsetHeight + 56) + 'px)';
        }, 0);
      });
      // 开始观察目标元素
      resizeObserver.observe(target);

      // 存储 resizeObserver 实例，以便在组件销毁时停止观察
      this.resizeObserver = resizeObserver;
    },
    // 跳转判断的
    hrefQueryFunc(cb) {
      let query = this.$route.query;
      if (JSON.stringify(query) != "{}") {
        this.formSearch.project_name = query.project_name || '';//筛选项目名
        this.formSearch.to_do = query.to_do || '0';//是否待处理
      }
      cb && cb();
    },
    // 提交导出数据
    exportSubmitFunc() {
      let exportrVal = this.exportrVal;
      let exportArr = this.exportArr;
      if (!this.exportrVal.length) {
        this.$message({
          type: 'warning',
          message: "请勾选需要导出的字段"
        })
        return;
      }
      let field_list = [];
      exportrVal.forEach(item => {
        let index = exportArr.findIndex(i => {
          return i.label == item;
        })
        if (index != -1) {
          field_list.push(exportArr[index].value)
        }
      })
      // console.log(field_list, "已勾选字段")
      this.$store.commit('exportProjectFunc', {
        field_list,
        total: this.total,
        formSearch: this.formSearch
      });
      this.exportCloseFunc();
    },
    // 全选导出字段
    allCheckedChangeFunc(e) {
      let exportrVal = [];
      let exportArr = this.exportArr;
      if (e) {
        exportArr.forEach(item => {
          exportrVal.push(item.label);
        })
        this.exportrVal = exportrVal//已选择字段
      } else {
        this.exportrVal = exportrVal//已选择字段
      }
    },
    // 关闭导出弹窗
    exportCloseFunc() {
      this.exportVisible = false;
      this.exportUrl = '';
      this.exportrVal = [];
      this.allChecked = false;
    },
    // 确认增减项
    QRzjxFunc() {
      this.qrzjxVisible = true;
    },
    // 对客报价
    DKquotationFunc() {
      this.$store.commit('isEventTriggeredFunc', true);
      let { id } = this.multipleSelection[0];
      this.$confirm('是否将报价单推送给客户?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        projectApi
          .toCustomerQuotation({
            project_id: id,
            remark: '',
            old_amount: '',
            new_amount: '',
            discount_amount: ''
          })
          .then((res) => {
            console.log(res, "对客报价");
            this.diaLoading = false;
            if (res.code == 200) {
              this.onSearch();
            }
            this.$message({
              type: res.code == 200 ? "success" : "warning",
              message: res.code == 200 ? "处理成功" : res.message,
            });
          })
          .catch((err) => {
            this.$message({
              type: "warning",
              message: err.message,
            });
          });
      }).catch(() => {

      });
      // this.$router.push({
      //   path: '/dkbjCom',
      //   query: {
      //     id
      //   }
      // })
    },
    // 申请报价
    SQquotationFunc() {
      this.$store.commit('isEventTriggeredFunc', true);
      let { id } = this.multipleSelection[0];
      this.$router.push({
        path: '/sqbjCom',
        query: {
          id
        }
      })
    },
    // table单行点击
    handleHighlightChangeTable(row) {
      if (!row.disabled) {
        this.$refs.table.toggleRowSelection(row);
      }
    },
    getnewurl() {
      let url = document.location.href;
      let reg = /[^\w](id)=?([^&|^#]*)/g;
      url = url.replace(reg, "");
      reg = /&&/g;
      url = url.replace(reg, "");
      reg = /&#/g;
      url = url.replace(reg, "#");
      reg = /\?#/g;
      url = url.replace(reg, "#");
      // url = url.replaceAll(document.domain,"");
      // url = url.replaceAll("http://","");
      // url = url.replaceAll("https://","");
      reg = /\?#/g;
      url = url.replace(reg, "#");
      return url;
    },
    // 单页数据量修改
    handleSizeChange(e) {
      this.num = e;
      this.onSearch(1);
    },
    // 搜索
    onSearch(page) {
      this.page = typeof page == 'number' ? page : this.page;
      this.saleProjectList();
    },
    // 翻页
    handleCurrentChange(page) {
      this.onSearch(page);
    },
    moreSearchFunc() {
      this.moreSearchShow = !this.moreSearchShow;
      this.$nextTick(() => {
        this.handleResize();
      })
    },
    // 添加项目
    addProjectFunc() {
      this.$store.commit('isEventTriggeredFunc', true);
      this.$router.push({
        path: '/addProject',
        query: {
          route_title: '添加项目'
        }
      })
    },
    // 项目列表
    saleProjectList() {
      let formSearch = this.formSearch;
      this.pageLoading = true;
      saleApi
        .saleProjectList({
          page: this.page,
          num: this.num,
          to_do: formSearch.to_do || 0,
          brand_id: formSearch.brand_id || '',
          store_type_id: formSearch.store_type_id || '',
          project_name: formSearch.project_name || '',
          project_number: formSearch.project_number || '',
          display_status: formSearch.display_status[0] == this.STATUS_CONSTANTS.SIGNED ?
            this.STATUS_CONSTANTS.SIGNED_SUB_STATUSES : formSearch.display_status,
          // created_at: formSearch.created_at,
          province_id: formSearch.city ? formSearch.city[0] : '',
          city_id: formSearch.city ? formSearch.city[1] : '',
          county_id: formSearch.city ? formSearch.city[2] : '',
          created_at_start: formSearch.created_at ? formSearch.created_at[0] : '',
          created_at_end: formSearch.created_at ? formSearch.created_at[1] : '',
          overall_rating: formSearch.overall_rating || '',
          account_manager_id: formSearch.account_manager_id || '',
          engineering_manager_id: formSearch.engineering_manager_id || '',
          engineering_supervision_id: formSearch.engineering_supervision_id || '',
          user_name: formSearch.user_name || '',
          contract_commencement_date_start: formSearch.contract_commencement_date ? formSearch.contract_commencement_date[0] : '',
          contract_commencement_date_end: formSearch.contract_commencement_date ? formSearch.contract_commencement_date[1] : '',
          contract_completion_date_start: formSearch.contract_completion_date ? formSearch.contract_completion_date[0] : '',
          contract_completion_date_end: formSearch.contract_completion_date ? formSearch.contract_completion_date[1] : '',
          construction_status: formSearch.construction_status || '',
          acceptance_progress: formSearch.acceptance_progress || '',
          risk_label: formSearch.risk_label || "",
          settlement_completion_date_start: formSearch.settlement_completion_date ? formSearch.settlement_completion_date[0] : '',
          settlement_completion_date_end: formSearch.settlement_completion_date ? formSearch.settlement_completion_date[1] : '',
          warranty_deadline_date_start: formSearch.warranty_deadline_date ? formSearch.warranty_deadline_date[0] : '',
          warranty_deadline_date_end: formSearch.warranty_deadline_date ? formSearch.warranty_deadline_date[1] : '',
        })
        .then((res) => {
          console.log(res, "项目列表");
          this.pageLoading = false;
          if (res.code == 200) {
            this.tableData = res.data.list;
            this.total = res.data.max;
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch((err) => {
          this.pageLoading = false;
          this.$message.warning(err.message);
        });
    },
    // 项目详情
    goToDetail(row) {
      this.$store.commit('isEventTriggeredFunc', true);
      this.$router.push({ path: "/projectDetailNew", query: { id: row.id } });
    },
    // 品牌列表
    getBrandList() {
      brandApi
        .getBrandList({
          page: 1,
          num: 9999,
          keyword: "",
        })
        .then((res) => {
          console.log(res, "品牌列表");
          if (res.code == 200) {
            this.brandList = res.data.list;
          }
        })
        .catch(() => { });
    },
    // 客户经理
    getAccountManager() {
      var obj = {
        page: 1,
        num: 999,
        keyword: "",
        province_id: "",
        city_id: "",
        county_id: "",
        identity: 1,
        position_id_arr: [2],
      };
      adminApi
        .getAdminList(obj)
        .then((res) => {
          console.log(res, "客户经理");
          if (res.code == 200) {
            this.accountManagerList = res.data.list;
          }
        })
        .catch((err) => { });
    },
    // 工程经理
    getEngineeringManager() {
      var obj = {
        page: 1,
        num: 9999,
        keyword: "",
        province_id: "",
        city_id: "",
        county_id: "",
        identity: 2,
        position_id_arr: [7],
      };
      adminApi
        .getAdminList(obj)
        .then((res) => {
          console.log(res, "工程经理");
          if (res.code == 200) {
            this.engineeringManagerList = res.data.list;
          }
        })
        .catch((err) => { });
    },
    // 客户
    getCustomer() {
      var obj = {
        page: 1,
        num: 9999,
      };
      adminApi
        .getUserList(obj)
        .then((res) => {
          console.log(res, "客户");
          if (res.code == 200) {
            this.customerList = res.data.list;
          }
        })
        .catch((err) => { });
    },
    handleSelectionChange(e) {
      console.log(e);
      console.log(e.length ? e[0].status : '', this.userInfo.position_id)
      this.multipleSelection = e;
    },
    // 设计师列表
    getAdminList() {
      var obj = {
        page: 1,
        num: 9999,
        keyword: "",
        province_id: "",
        city_id: "",
        county_id: "",
        identity: 1,
        position_id_arr: [3],
      };
      adminApi
        .getAdminList(obj)
        .then((res) => {
          console.log(res, "设计师列表");
          if (res.code == 200) {
            this.designerList = res.data.list;
          } else {
            this.$message({
              message: res.message,
              type: "warning",
            });
          }
        })
        .catch((err) => { });
    },
    // 项目启动  是否勘场选择
    surveySiteChangeFunc(type) {
      this.formInlineStart = {
        survey_site: type,
        designer_id: "",
        survey_date: "",
      }
    },
    // ------------------------项目操作---------------------------------
    // 项目启动
    startProjectFunc() {
      this.dialogVisibleStart = true;
      this.getAdminList();
    },
    cancelStartFunc() {
      this.formInlineStart = {
        survey_site: 1,
        designer_id: "",
        survey_date: "",
      }
      this.dialogVisibleStart = false;
    },
    submitStartFunc() {
      this.$refs.ruleFormStart.validate((valid) => {
        if (valid) {
          let designerData = null;
          if (this.formInlineStart.designer_id) {
            designerData = this.designerList.find((item) => {
              return item.id == this.formInlineStart.designer_id;
            });
          }
          this.startLoading = true;
          projectApi.chooseSurveySite({
            project_id: this.multipleSelection[0].id,
            survey_site: this.formInlineStart.survey_site,
            designer_id: this.formInlineStart.designer_id,
            designer_name: designerData ? designerData.name : '',
            survey_date: this.formInlineStart.survey_date,
          }).then(res => {
            console.log(res, "项目启动");
            this.startLoading = false;
            if (res.code == 200) {
              this.dialogVisibleStart = false;
              this.$message({
                message: res.message,
                type: "success",
              });
              this.onSearch();
            } else {
              this.startLoading = false;
              this.$message({
                message: res.message,
                type: "warning",
              });
            }
          })
            .catch((err) => {
              this.$message.warning(err.message);
            });
        } else {
          return false;
        }
      });
    },
    // 完善项目
    editProjectFunc() {
      this.$store.commit('isEventTriggeredFunc', true);
      this.$router.push({
        path: '/addProject',
        query: {
          id: this.multipleSelection[0].id,
          route_title: "完善项目"
        }
      })
    },
    // 修改人员
    changeManFunc() {
      this.changeManVisible = true;
    },
    // 修改人员请求成功
    changeManSuccessFunc() {
      this.onSearch();
      this.changeManVisible = false;
    },
    // 分配客户经理
    FPassignAccountManagerFunc() {
      this.fpkhjlVisible = true;
    },
    // 分配客户经理成功回调
    FPassignAccountManagerOnSuccess() {
      this.onSearch();
      this.fpkhjlVisible = false;
    },
    // 门店类型列表
    getStoreTypeList() {
      storeTypeApi.getStoreTypeList({
        page: 1,
        num: 999
      }).then(res => {
        console.log(res, "门店类型列表")
        if (res.code == 200) {
          this.storeTypeList = res.data.list;
        }
      })
    },
    // 省市区
    getAreaList() {
      commonApi.getAreaList().then(res => {
        console.log(res, '’省市区')
        if (res.code == 200) {
          this.areaList = res.data;
        }
      })
    },
    // 工程监理列表
    getEngineeringSupervision() {
      adminApi.getAdminList({
        page: 1,
        num: 9999,
        identity: 1,
        position_id_arr: [8],
      }).then(res => {
        console.log(res, "工程监理列表")
        if (res.code == 200) {
          this.engineeringSupervisionList = res.data.list;
        }
      })
    },
    // 项目取消
    XmcancelFunc() {
      this.xmqxVisible = true;
    },
    // 项目取消操作回调
    XmcancelOnSuccess() {
      this.onSearch();
      this.xmqxVisible = false;
    },
    // 确认增减项回调
    QRzjxOnSuccess() {
      this.onSearch();
      this.qrzjxVisible = false;
    },
    // 批量删除项目
    delProjectFunc() {
      this.$confirm("此操作将永久删除已勾选项目, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let multipleSelection = this.multipleSelection;
          let id_arr = [];
          multipleSelection.forEach(item => {
            id_arr.push(item.id);
          })
          this.delProject(id_arr);
        })
        .catch(() => { });
    },
    // 删除项目请求
    delProject(id_arr) {
      projectApi
        .delProject({ id_arr, remark: "" })
        .then((res) => {
          console.log(res, "删除项目");
          if (res.code == 200) {
            this.$message.success("删除成功");
            this.onSearch();
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch((err) => {
          this.$message.warning(err.message);
        });
    },
    // 项目回退
    adminBackSubmit() {
      if (!this.backValue) {
        this.$message.warning("请选择回退目标");
        return;
      }
      this.backLoading = true;
      projectApi
        .projectRollback({
          status: this.backValue,
          project_id: this.multipleSelection[0].id,
          remark: "",
        })
        .then((res) => {
          this.backLoading = false;
          console.log(res, "回退");
          if (res.code == 200) {
            this.onSearch();
            this.adminBackShow = false;
          }
          this.$message({
            type: res.code == 200 ? "success" : "warning",
            message: res.code == 200 ? "处理成功" : res.message,
          });
        })
        .catch((err) => {
          this.$message.warning(err.message);
          this.backLoading = false;
        });
    },
    adminBackDataFunc() {
      console.log(backdata1)
      console.log(backdata2)
      let backOptions = [];
      let multipleSelection = this.multipleSelection[0];
      console.log(multipleSelection)
      let backData = '';
      switch (Number(multipleSelection.survey_site)) {
        case 1:
          backData = backdata1;
          break;
        case 2:
          backData = backdata2;
          break;
        case 3:
          backData = backdata3;
          break;
        default:
      }
      // 如果不是用户创建的项目不能回退（是否勘场）
      // if (multipleSelection.source != 3) {
      //   let index = backData.findIndex(item => {
      //     return item.value == 1010;
      //   })
      //   backData.splice(index, 1);
      // }
      backData.forEach(item => {
        if (Number(item.value) < Number(multipleSelection.status)) {
          backOptions.push(item);
        }
      })
      this.backOptions = backOptions;
      this.backValue = '';
      this.adminBackShow = true;
    },
    // 重新结算（回退至结算）
    projectsSettlementFunc() {
      this.$confirm('确认回退至出具结算单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        projectApi
          .projectRollback({
            status: 1130,
            project_id: this.multipleSelection[0].id,
            remark: "",
          })
          .then((res) => {
            console.log(res, "回退结算");
            if (res.code == 200) {
              this.onSearch();
            }
            this.$message({
              type: res.code == 200 ? "success" : "warning",
              message: res.code == 200 ? "处理成功" : res.message,
            });
          })
          .catch((err) => {
            this.$message.warning(err.message);
          });

      }).catch(() => { });
    },
    // 重新报价（回退至报价）
    projectsQuoteFunc() {
      this.$confirm('确认回退至造价员报价?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        projectApi.reQuote({
          project_id: this.multipleSelection[0].id
        }).then(res => {
          console.log(res, "重新报价")
          if (res.code == 200) {
            this.onSearch();
          }
          this.$message({
            type: res.code == 200 ? 'success' : 'warning',
            message: res.code == 200 ? '处理成功' : res.message
          });
        })
      }).catch(() => { });
    },
    //-----------------------------收款单------------------------
    // 添加收款单
    addReceiptFunc() {
      this.getCompanyList();
      this.formInlineReceipt.receiving_account_id = this.multipleSelection[0].receiving_account_id || '';
      this.formInlineReceipt.project_id = this.multipleSelection[0].id;
      this.formInlineReceipt.project_name = this.multipleSelection[0].project_name;
      // 获取项目已收未收
      commonApi.selectProjectDetails({ project_id: this.multipleSelection[0].id }).then(res => {
        console.log(res, "项目基本信息")
        if (res.code == 200) {
          this.formInlineReceipt.unpaid_amount = res.data.unpaid_amount || '0';//未收
          this.formInlineReceipt.paid_amount = res.data.paid_amount || '0';//已收
          this.formInlineReceipt.receiving_account_id = res.data.receiving_account_id || '';//收款账户
        }
      })
      this.dialogVisibleReceipt = true;
    },
    cancelReceiptFunc() {
      this.formInlineReceipt = {
        project_id: "",
        payment_type: "",
        amount_collected: "",
        remark: "",
        receiving_account_id: "",
        payment_voucher: [],
        change_id: "",
        settlementMsg: '',
        unpaid_amount: '',
        paid_amount: ''
      }
      this.dialogVisibleReceipt = false;
    },
    // 删除支付凭证
    delFileFunc(index) {
      // let delete_arr = [];
      let formInlineReceipt = this.formInlineReceipt;
      if (formInlineReceipt.payment_voucher[index].file_id) {
        formInlineReceipt.delete_arr.push(formInlineReceipt.payment_voucher[index]);
      }
      formInlineReceipt.payment_voucher.splice(index, 1);
      this.formInlineReceipt = formInlineReceipt;
    },
    // 上传支付凭证
    paymentVoucherFileFunc(e) {
      console.log(e)
      let formInlineReceipt = this.formInlineReceipt;
      formInlineReceipt.payment_voucher = [e];
      this.formInlineReceipt = formInlineReceipt;
    },
    // 收款账户
    getCompanyList() {
      companyApi.getCompanyList({
        page: 1,
        num: 999,
        account_type: 1
      }).then(res => {
        console.log(res, "主体账户列表")
        if (res.code == 200) {
          this.companyList = res.data.list;
        }
      })
    },
    // 收款单  收款类型选择
    paymentTypeChangeFunc(e) {
      if (e == 4) {
        // 尾款获取结算单列表
        this.getSettlementList(this.formInlineReceipt.project_name);
      }
      if (e == 5) {
        // 增项款获取增减项列表
        this.getChangeList(this.formInlineReceipt.project_name);//增项列表
      }
    },
    // 增项列表
    getChangeList(project_name) {
      increaseDecreaseItemsApi.getChangeList({
        page: 1,
        num: 999,
        increase_or_decrease: 1,
        project_name: project_name || ''
      }).then(res => {
        console.log(res, "增项列表")
        if (res.code == 200) {
          this.changeList = res.data.list;
        }
      })
    },
    // 结算列表
    getSettlementList(project_name) {
      preSettlementApi.getSettlementList({
        page: 1,
        num: 10,
        project_name
      }).then(res => {
        console.log(res, "结算列表")
        if (res.code == 200) {
          this.formInlineReceipt.settlementMsg = res.data.list[0];
        }
      })
    },
    submitReceiptFunc() {
      let formInlineReceipt = this.formInlineReceipt;
      let changeList = this.changeList;//增项列表
      let payTypeList = this.payTypeList;//付款类型
      let companyList = this.companyList;//收款账户
      console.log(formInlineReceipt, "formInlineReceipt")
      this.$refs.ruleFormReceipt.validate((valid) => {
        if (valid) {
          let formdata = new FormData();
          // 增项款编号
          let index1 = changeList.findIndex(item => {
            return item.id == formInlineReceipt.change_id;
          })
          // 付款类型名称
          let index2 = payTypeList.findIndex(item => {
            return item.id == formInlineReceipt.payment_type;
          })
          // 收款账户
          let index4 = companyList.findIndex(item => {
            return item.id == formInlineReceipt.receiving_account_id;
          })

          let data = {
            amount_collected: formInlineReceipt.amount_collected,
            payment_type: formInlineReceipt.payment_type,
            payment_name: index2 != -1 ? payTypeList[index2].label : "",
            project_id: formInlineReceipt.project_id,
            project_name: formInlineReceipt.project_name,
            receiving_account_id: formInlineReceipt.receiving_account_id,
            account_name: index4 != -1 ? companyList[index4].account_name : "",
            remark: formInlineReceipt.remark,
            change_id: formInlineReceipt.change_id,
            change_number: index1 != -1 ? changeList[index1].change_number : "",
          }
          for (let i = 0; i < formInlineReceipt.payment_voucher.length; i++) {
            if (formInlineReceipt.payment_voucher[i].raw) {
              formdata.append('payment_voucher[]', formInlineReceipt.payment_voucher[i].raw);
            }
          }
          formdata.append('data', JSON.stringify(data));
          this.addReceipt(formdata);
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 新增收款单请求
    addReceipt(obj) {
      this.addLoading = true;
      companyApi.addReceipt(obj).then(res => {
        console.log(res, "添加收款单")
        this.addLoading = false;
        if (res.code == 200) {
          this.onSearch();
          this.cancelReceiptFunc();
        }
        this.$message({
          type: res.code == 200 ? 'success' : 'warning',
          message: res.message
        })
      })
    },
    // 查看结算单详情
    goSettlementMsFunc() {
      this.$store.commit('isEventTriggeredFunc', true);
      this.$router.push({
        path: "/settlemenDetailPage?id=" + this.formInlineReceipt.settlementMsg.id,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import './index.scss';
@import '@/styles/listPage.scss';
</style>